Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting float to integer in LitterBox translation #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Casting float to integer in LitterBox translation #1

wants to merge 2 commits into from

Conversation

emmableu
Copy link
Contributor

To resolve a bug that - when translating a Scratch program that has floating points in "change x by", "change y by", it gives an error: Exception in thread "main" java.lang.RuntimeException: Expected type integer but got 5.5, we have casted all float literals to int unless expectFloat is explicit.

However, this may have caused us to cast some that are not supposed to be integers to integers. So please let us know if there are other ways to change the translation method.

@Nina-Nicole
Copy link
Contributor

Thank you for your pull request!

However, this may have caused us to cast some that are not supposed to be integers to integers. So please let us know if there are other ways to change the translation method.

You are right here - you propose to use integer even if the ORIGINAL type is expected - we suggest to round floats to ints only if it is explicitly expected.

Furthermore, casting floats to ints cuts off the decimal places instead of rounding. That results in unneccessary imprecision and we suggest to use round() instead of casts.

In the long term we also consider to allow floats for the "change x by" and "change y by" blocks, as rounding floats in general discards relevant information, so why not keep it 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants